<?php

/*
 *  This file is part of Urd.
 *
 *  Urd is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  Urd is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. See the file "COPYING". If it does not
 *  exist, see <http://www.gnu.org/licenses/>.
 *
 * $LastChangedDate: 2008-07-12 15:43:11 +0200 (Sat, 12 Jul 2008) $
 * $Rev: 1291 $
 * $Author: gavinspearhead $
 * $Id: pr_file.php 1291 2008-07-12 13:43:11Z gavinspearhead $
 */

// This is an include-only file:
if (!defined('ORIGINAL_PAGE')) die('This file cannot be accessed directly');


class pr_file {
	public $ext;  // extension
	public $base; // basename
	public $files; // file set

	function __construct ($ext, $base, $filename)
	{
		assert ($ext != '' && $filename != '');
		$this->ext = $ext;
		$this->base = $base;
		$this->files [] = $filename;
	}
}


class pr_list {
	public $file_list;
	public $dir;
	function __construct($dir) { 
		assert($dir != '');
		$this->file_list = array();
		$this->dir = $dir;
	}

	function add ($ext, $base, $filename)
	{
		assert ($ext != '' && $filename != '');
		foreach ($this->file_list as $f) {
			if (($f->ext == $ext) && ($f->base == $base)) {
				$f->files[] = $filename;
				return ;
			}
		}
		$this->file_list[] = new pr_file($ext, $base, $filename);
	}
	function delete_files($par=FALSE, $archives=FALSE, $sfv=FALSE, $uue=FALSE, $cat=FALSE)
	{
		assert(is_bool($par) && is_bool($archives) && is_bool($sfv) && is_bool($uue) && is_bool($cat));
		foreach ($this->file_list as $f) {
			if ((($archives === TRUE) && in_array($f->ext, array(RAR_EXT, ACE_EXT, ARJ_EXT, ZIP_EXT, ZR7_EXT))) ||
				(($par === TRUE) && ($f->ext == PAR_EXT)) ||
				(($cat === TRUE) && ($f->ext == CAT_EXT)) ||
				(($uue === TRUE) && ($f->ext == UUE_EXT)) ||
				(($sfv === TRUE) && ($f->ext == SFV_EXT))) 
				delete_files($f->files, $this->dir);
		}
	}
}

?>
